using UnityEngine;
using System.Collections;

/// \class  gkSpawningOnTopOfTheScreen
/// \brief  Place the spawned actor on top of the screen
[AddComponentMenu("GK/Engine/Game/Spawn/gkSpawningOnTopOfTheScreen")]
public class gkSpawningOnTopOfTheScreen : gkSpawningModifier 
{
	/// The spawning volume bounding box
	private Bounds m_oSpawningVolumeBoudingBox;
	
	/// \brief  Called just after the game begin to play
	void Start()
	{
		// Get the spawning volume bounding box
	   gkUtilityBounds.GrabColliderOrRendererBounds(GameObject.Find("GameVolume"), out m_oSpawningVolumeBoudingBox);
	}
	
	/// \brief  Event called at the and of the actor spawn
	public override void ModifySpawnedActor(GameObject a_rSpawnedActor, int a_iNumActorsInCurrentBatch, int a_iNbActorsInCurrentBatch)
	{
		PlaceSpawnedActorInFrontOfTheScreen(a_rSpawnedActor);
	}
	
	/// \brief  Place the spawned actor just out of the screen
	void PlaceSpawnedActorInFrontOfTheScreen(GameObject a_rSpawnedActor)
	{
		Vector3 f3SpawnedPosition;
		Bounds rSpawnedActorBounds;
		
		// Grab the spawned actor bounds
		 gkUtilityBounds.GrabRendererOrColliderBounds(a_rSpawnedActor, out rSpawnedActorBounds);
	
		f3SpawnedPosition = a_rSpawnedActor.transform.position;
		
		// Change the Y coordinate in order to place the spawned actor just out of the screen
		f3SpawnedPosition.y = m_oSpawningVolumeBoudingBox.max.y
			+ rSpawnedActorBounds.extents.y;
	
		a_rSpawnedActor.transform.position = f3SpawnedPosition;
	}
}